﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace NSAdapter
{
    public class CircuitAdapter
    {
        public CircuitAdapter()
        {
        }

        public bool addGate(int x, int y, string type)
        {
            return _addGate(x, y, type);
        }

        public bool removeGate(int x, int y)
        {
            return _removeGate(x, y);
        }

        public bool addConnection(int x1, int y1, int x2, int y2)
        {
            return _addConnection(x1, y1, x2, y2);
        }

        public bool removeConnection(int x1, int y1, int x2, int y2)
        {
            return _removeConnection(x1, y1, x2, y2);
        }

        public string getDrawingInstruction()
        {
            return _getDrawingInstruction();
        }

        public string serialize()
        {
            return _serialize();
        }

        public bool deserialize(string serializedCircuit)
        {
            return _deserialize(serializedCircuit);
        }

        public void clearCircuit()
        {
            _clearCircuit();
        }

        // imported methods from the unmanaged dll, they are basically C style functions
        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern bool _addGate(int x, int y, string type);

        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern bool _removeGate(int x, int y);

        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern bool _addConnection(int x1, int y1, int x2, int y2);

        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern bool _removeConnection(int x1, int y1, int x2, int y2);

        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern string _getDrawingInstruction();

        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern string _serialize();

        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern bool _deserialize(string serializedCircuit);

        [DllImport("..\\..\\..\\..\\business\\bin\\Dll\\circsim.dll", CallingConvention = CallingConvention.Cdecl, SetLastError = true)]
        static extern void _clearCircuit();
    }
}
